﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ChartString.cs" company="">
//   
// </copyright>
// <summary>
//   The chart string.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Graphix.Elements
{
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using SvgNet.SvgGdi;

    /// <summary>
    /// The chart string.
    /// </summary>
    public class ChartString : BaseElement
    {
        #region Fields

        /// <summary>
        /// The height.
        /// </summary>
        public float Height;

        /// <summary>
        /// The width.
        /// </summary>
        public float Width;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ChartString"/> class.
        /// </summary>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <param name="y">
        /// The y.
        /// </param>
        /// <param name="width">
        /// The width.
        /// </param>
        /// <param name="height">
        /// The height.
        /// </param>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="font">
        /// The font.
        /// </param>
        /// <param name="color">
        /// The color.
        /// </param>
        /// <param name="group">
        /// The group.
        /// </param>
        public ChartString(float x, float y, float width, float height, string text, 
                           Font font, Brush color = null)
            : base(x, y, color)
        {
            this.Text = text;
            this.Font = font;
            this.Format = new StringFormat();

            this.Width = width;
            this.Height = height;
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the font.
        /// </summary>
        public Font Font { get; set; }

        /// <summary>
        /// Gets or sets the format.
        /// </summary>
        public StringFormat Format { get; set; }

        /// <summary>
        /// Gets or sets the rotation.
        /// </summary>
        public float Rotation { get; set; }

        /// <summary>
        /// Gets or sets the text.
        /// </summary>
        public string Text { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The draw.
        /// </summary>
        /// <param name="graphics">
        /// The graphics.
        /// </param>
        public override void Draw(IGraphics graphics)
        {
            if (!string.IsNullOrEmpty(this.Text))
            {
                if (this.Rotation != 0)
                {
                    graphics.RotateTransform(this.Rotation, MatrixOrder.Append);
                    graphics.TranslateTransform(this.Position.X, this.Position.Y, MatrixOrder.Append);

                    // graphics.TranslateTransform(PositionR.X, PositionR.Y, MatrixOrder.Append);
                    graphics.DrawString(this.Text, this.Font, this.Color, 0, 0, this.Format,
                        this.Attributes);
                    graphics.ResetTransform();
                }
                else
                {
                    graphics.DrawString(this.Text, this.Font, this.Color, this.Position.X,
                        this.Position.Y, this.Format, this.Attributes);
                }
            }
        }

        #endregion
    }
}